package Internet;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictServer extends UdpEchoServer{
    private HashMap<String,String> hashMapDict=new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);
        //初始化词典
        hashMapDict.put("cat","小猫");
        hashMapDict.put("dog","小狗");
        hashMapDict.put("pig","小猪");
        hashMapDict.put("snake","小蛇");
        hashMapDict.put("chicken","小鸡");
    }
    @Override
    public String process(String request) {
        return hashMapDict.getOrDefault(request,"未找到该单词");

    }
    public static void main(String[] args) throws IOException {
        //端口与服务器端口号同
        UdpDictServer udpDictServer=new UdpDictServer(1777);
        udpDictServer.start();
    }
}
